package com.umeox.watch.moto.chat.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.umeox.watch.moto.chat.R

/**
 * Created by Rambo 2021/9/6
 * Describe:
 */
class QuickReplyAdapter(val context: Context) : RecyclerView.Adapter<QuickReplyAdapter.QRHolder>() {

    private lateinit var quickReplyStr: Array<String>

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): QRHolder {
        val view: View =
            LayoutInflater.from(parent.context).inflate(R.layout.item_quick_reply, parent, false)
        return QRHolder(view)
    }

    override fun onBindViewHolder(holder: QRHolder, position: Int) {
        val currentStr = quickReplyStr[position]
        holder.mQuickReplyTv.text = currentStr
        holder.itemView.setOnClickListener {
            if(mOnItemClickListener != null){
                mOnItemClickListener!!.invoke(currentStr)
            }
        }
    }

    override fun getItemCount(): Int {
        quickReplyStr = context.resources.getStringArray(R.array.quick_reply_arr)
        return quickReplyStr.size
    }

    inner class QRHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
        val mQuickReplyTv: TextView = itemView.findViewById(R.id.tv_quick_reply)

    }

    private var mOnItemClickListener: ((quickReplyStr: String) -> Unit)? = null

    fun setOnItemClickListener(onItemClickListener: (quickReplyStr: String) -> Unit) {
        mOnItemClickListener = onItemClickListener
    }

}